<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html> 
<head>
<%@ include file="../../include/easyui.jsp" %>
<%@ include file="../../include/pGrid.jsp" %>
<script type="text/javascript" src="/plug-in/jquery-easyui-1.5.1/datagrid-detailview.js"></script>
<title>工程支出查看</title>
<script>
/**
 * 通过工程路段编号显示相关工程信息
 */
	function showProject(pNo){
		setTimeout(function(){
			p.gridOpt({href:'/console/project/config?pNo='+ pNo, title : "更多项目详情", width : 850, height : 430 ,autoMax:true});
		},1);
	}
	function childTotal(grid){
		var dData = grid.datagrid('getData');
		var total = {money: 0, costType: '合计：'};
		$.each(dData.rows ||[], function (i,item) {
			total.money += parseFloat(item.money || '0');
		});
		total.money = total.money.toFixed(2);
		grid.datagrid('appendRow',total);
	}
	
	function showComment(processInstanceId){
		p.gridAdd({
			href:'/console/activiti/comment/index?processInstanceId='+ processInstanceId, title : "审批状态批注信息", width : 650, height : 430
			,buttons : [p.buttons.close ]	
		});
	}
	
	$(function(){
		var sa = '${SESSION_USER.isSysAdm}';
		var gridParam = {
			url:"/console/com.fs.jzzn.pojo.Expense/list",
			sort:"createTime",
			order:"desc",
			columns:[[
			          {"field": "expenseNo", "title": "单据编号", "width": 120}
			    	 ,{"field": "applyDate", "title": "申请日期", "width": 120}
			    	 ,{"field": "pm", "title": "申请人", "width": 100}
			    	 ,{"field": "status", "title": "审批状态", "width": 100,formatter: function(value,row,index){
			    		 if( row.processInstanceId){
				    		 return '<a href="#" onclick="showComment('+ row.processInstanceId +')">'+ value +'</a>'
			    		 }else{
			    			 return value;
			    		 }
			    	 }}
			    	 ,{field : "department",width : 120,title: "关联项目部"}
			    	 ,{field : "contractName",width : 120,title: "合同名称(G)"}
					,{field : "remark",width : 150,title: "备注"}
					,{field : "createTime",width : 130,title: "创建时间"}
					,{field : "createrName",width : 130,title: "创建人"}
			]],
			onLoadSuccess: function(){
				p.tooltip(['billsNo','msg','remark']);
			},
			view: detailview,
			detailFormatter:function(index,row){
				return '<div class="details" style="padding:5px 0;min-height:200px;"></div>';
			},
			onExpandRow:function(index,row){
				var ddv = $(this).datagrid('getRowDetail',index).find('div.details');
				var detailGrid = ddv.datagrid({
					url : '/console/com.fs.jzzn.pojo.ExpenseItem/list',
					queryParams: {
						expenseNo :row.expenseNo,
						expenseNo_searchType: "eq"
					},
					title:'支出明细-'+ row.expenseNo,
					pageSize:30,
					rownumbers: true,
					pagination: true,
					singleSelect: true, 
					nowrap:false,
					columns : [[
							{field: 'costUser', title: '支出对象', width: 120,editor:'textbox'}
							,{field: 'remark', title: '标题说明', width: 200,editor:'textbox'}
						    ,{field: 'costType', title: '类别', width: 100}
					    	,{field: 'money', title: '金额(元)', width: 80,editor:{type:'numberbox',options:{precision:2}}}
					    	,{field: 'billsNo', title: '凭单号', width: 150,editor:'textbox'}
					    	,{field: 'pNo', title: '路段编号', width: 130}
					    	,{field: 'department', title: '关联项目部', width: 130}
					    	,{field: 'costDate', title: '支出日期', width: 100}
					]],
					onLoadSuccess:function(){
						$('#dataGrid').datagrid('fixDetailRowHeight',index);
						childTotal(ddv);
					},
					toolbar: [
				          { iconCls: 'icon-excel', text:'支出明细导出',handler: function(){
				        	  p.down({filename:'支出明细-'+ row.expenseNo,local :true,grid:detailGrid});
				          }}
					]
				});
			}
		};
		p.dataGrid = $(p.dataGrid).datagrid($.extend({}, p.dataGridParam,gridParam));
		/*事件响应*/
		$("#toolbar .easyui-linkbutton").on("click", function() {
			var motion_code = $(this).attr("motion_code");p.btnOneClick($(this));
			switch (motion_code) {
				case "04":
					p.gridView({title : "支出查看" ,width : 650, height : 460 ,autoMax:true});
					break;
				case "05":
					p.gridQuery();
					break;
				case "07":
					p.down({filename:'工程支出'});
					break;
				case "19":
					p.gridAdd({href:'/console/expense/import', title : "工程支出数据导入", width : 550, height : 330 });
					break;
				default:
					break;
				}
		});
	});
</script>
</head>
<body class="easyui-layout">
	<!-- 但行高度33px，多行时 33乘以行数  -->
	<div data-options="region:'north',split:false,border:false" style="height:auto;">
		<div class="easyui-panel" data-options="fit:true,border:false">
			<!-- 查询条件表单，根据配置进行替换  -->
		<form id="queryForm" >
		 	<input type="hidden" name="className" value="com.fs.jzzn.pojo.Expense" />
		 	<div style="margin-top:5px;margin-left:10px;float:left;">
		  		<input class="easyui-textbox" name="expenseNo" style="width:240px;" data-options="label:'单据编号:',required:false,labelWidth:'70px'" />
		  		<input type="hidden" name="expenseNo_searchType" value="like" />
		 	</div>
		 	<div style="margin-top:5px;margin-left:10px;float:left;">
		    	<select class="easyui-combotreegrid" name="orgNo" style="width:240px;" data-options="label:'所属机构:',panelWidth:250,
	           	idField: 'orgNo', 
	           	missingMessage:'必填项',
				treeField: 'orgName',
				sortName:'orgOrder',
				onSelect:function(row){
					$('input[name=department]').val(row.orgName);	    
				},
				sortOrder:'asc',
	            url:'/console/com.fs.base.pojo.Org/list', 
	            queryParams:{isTreeGrid:'true', treeId:'id', treePid:'parentId' },
	            columns:[[    
	                {field:'orgName',			width:190,	title:'组织名称' }
	            ]]"></select>
		  		<input type="hidden" name="orgNo_searchType" value="like" />
		 	</div>
		 	
		 	<div style="margin-top:5px;margin-left:10px;float:left;">
		  		<input class="easyui-textbox" name="contractName" style="width:240px;" data-options="label:'合同名称:',required:false,labelWidth:'70px'" />
		  		<input type="hidden" name="contractName_searchType" value="like" />
		 	</div>
		 	
		 	<div class="fItem">
		  		<input class="easyui-combobox" name="createrId" style="width:240px;" url="/console/combobox?valueField=id&textField=nickName&modleName=user" data-options="label:'创建人:',required:false" />
		  		<input type="hidden" name="createrId_searchType" value="eq" />
		 	</div>
	 	
	 	<div class="fItem">
		 	<input class="easyui-datebox" style="width:240px;" name="createTime" data-options="label:'开始日期:',required:false" />
		 	<input type="hidden" name="createTime_searchType" value="between" />
		 	<input type="hidden" name="createTime_format" value="date" />
		</div>
		<div class="fItem">
		 	<input class="easyui-datebox" style="width:240px;" name="createTime" data-options="label:'截至日期:',required:false" />
		</div>
		</form>
		</div>
	</div> 
	<!-- 工具栏按钮 -->
	<div id="toolbar" class="easyui-panel" style="padding:3px;">
	</div>
	
	<!-- 表格 -->
	<div region="center" border="false">
		<table id="dataGrid"></table>
	</div>
</body>
</html>